/**author:yebinx email:yebinx@21cm.com*/
export default class HttpUtil {
    public static get(_url:string,_func:Function=null,_param:any=null){
        let xhr = new Laya.HttpRequest();
        xhr.http.timeout = 10000;//设置超时时间；
        xhr.once(Laya.Event.COMPLETE, this, (e) => {
            _func(xhr.data.data);
        });
        let tp = _param?JSON.stringify(_param):null;
        let tparam:string="";
        for(let key in _param){
            if(!tparam)tparam = (key+"="+_param[key]);
            else tparam += "&"+(key+"="+_param[key]);
        }
        let turl = _url+"?"+tparam
        xhr.send(turl, null, "get", "json", ["content-type", "application/json"]);
    }

    public static post(_url:string,_param:any=null,_func:Function=null){
        let xhr = new Laya.HttpRequest();
        xhr.http.timeout = 10000;//设置超时时间；
        xhr.once(Laya.Event.COMPLETE, this, (e) => {
            _func(xhr.data.data);
        });
        let tp = _param?JSON.stringify(_param):null;
        xhr.send(_url, tp, "post", "json", ["content-type", "application/json"]);
    }
}